<template>
	<view style="padding: 30rpx;">
		<view v-if="pageData.dataList.length>0">
			<view v-if="pageData.dataList[0].serviceType!='咨询服务'" class="serviceItem line1"
				v-for="item in pageData.dataList" @click="goDetail(item)">{{item.serviceName}}
			</view>
			<view v-else class="imgBox">
				<template v-for="item in pageData.dataList">
					<image class="mb30 img" v-for="(list,idx) in item.imgUrl.split(',')" :src="config.baseUrl+list"
						mode="widthFix" @click="previewImageFn(list)"></image>
				</template>
			</view>
		</view>
		<noData v-if="pageData.dataList.length<=0"></noData>
		<uni-load-more v-else :status="pageData.status"></uni-load-more>
	</view>
</template>

<script setup>
	import config from '@/common/config.js'
	import {
		ref,
		getCurrentInstance,
		nextTick
	} from "vue";
	import store from "@/store/index.js";
	const pageData = ref({
		dataList: [],
		status: 'noMore',
	})
	import {
		serviceList,
	} from "@/api/index.js";
	onLoad((opt) => {
		serviceList(({
			serviceType: opt.name,
			pageNum: 1,
			pageSize: 1000
		})).then((res) => {
			pageData.value.dataList = res.rows
		})
	})
	const goDetail = (item) => {
		uni.getSystemInfo({
			success: res => {
				console.log(res);
				if (res.platform === 'android') {
					uni.showLoading({
						title: '加载中'
					})
					uni.downloadFile({
						url: config.baseUrl + item.imgUrl,
						success: function(res) {
							const filePath = res.tempFilePath;
							uni.openDocument({
								filePath: filePath,
								success: function(res) {
									console.log('打开文档成功');
								},
								complete() {
									uni.hideLoading()
								}
							});
						}
					});
				} else {
					store.state.webUrl = config.baseUrl + item.imgUrl;
					uni.navigateTo({
						url: `/pages/webView/webView`
					})
				}
			}
		});
		// uni.navigateTo({
		// 	url: '/pages/fwtx/detail?id=' + item.id
		// })
	}
	const previewImageFn = (src, index) => {
		let urls = config.baseUrl + src
		console.log(urls);
		uni.previewImage({
			urls: [urls],
			current: 0,
			longPressActions: {
				success: function(data) {},
				fail: function(err) {}
			}
		});
	}
</script>

<style lang="scss" scoped>
	.serviceItem {
		height: 88rpx;
		font-size: 30rpx;
		border-bottom: 1px solid #eee;
		line-height: 88rpx;
	}

	.imgBox {
		.img {
			width: 100%;
			display: block;
		}
	}
</style>